/**************************************************************************************
 *  Copyright (c)  2010  Leszek Karcz, Changmin Bae.
 *  Permission is granted to copy, distribute and/or modify this document
 *  under the terms of the GNU Free Documentation License, Version 1.3
 *  or any later version published by the Free Software Foundation;
 *  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 *  A copy of the license is included in the section entitled "GNU
 *  Free Documentation License". 
 **************************************************************************************/
package data.tileables;
import data.Map;
import data.Player;
import data.missions.PowerDown;
import data.missions.PowerUp;

/**************************************************************************************
 * Author(s): Leszek Karcz, Changmin Bae
 * Laboratory building, needed to do research
 **************************************************************************************/
public class Laboratory extends Structure
{
	//TODO set price
	public static final int [] PRICE = { 30, 50, 50 };
	/**************************************************************************************
	 * Author(s): Leszek Karcz, Changmin Bae
	 * Laboratory constructor
	 **************************************************************************************/
	public Laboratory(int ID, int supertypeID, Player player, int workers)
	{
		super(ID, supertypeID, player, workers);
		this.setType("Laboratory");
		this.setImage("struct_lab");
		this.setIcon("struct_lab");
		this.setStats(5, 4, 100, 50, 0, 5, 1);
		this.setUpkeep(new int[]{0,2,2});
		this.setNumberOfCommands(3);
	}
	
	/**************************************************************************************
	 * Author(s): Leszek Karcz, Changmin Bae
	 * executes instructions regarding currently selected command
	 **************************************************************************************/
	public boolean enqueueSelectedCommand(String mode, Map m, int x, int y)
	{
		int selected=this.getSelectedCommand();
		if(this.isFinished())
		{
			if(getCommandMode() == 0)
			{
				switch(selected)
				{
					case 0:
						this.die();
						break;
					case 1:
						if(this.getState() == 0)
							this.addMission(new PowerUp(this));
						else
							this.addMission(new PowerDown(this));
						break;
					case 2: 
						setCommandMode(1);
						setNumberOfCommands(9);
						break;
				}
			}
			else if(getCommandMode() == 1)
			{
				if(mode == "Cancel")
				{
					setCommandMode(0);
					setNumberOfCommands(3);
					
				}
				switch(selected)
				{					
					case 0:
						setCommandMode(2);
						setNumberOfCommands(2);
						break;
					case 1:
						setCommandMode(3);
						setNumberOfCommands(6);
						break;
					case 2: 
						setCommandMode(3);
						setNumberOfCommands(6);
						break;
					case 3:
						setCommandMode(3);
						setNumberOfCommands(6);
						break;
					case 4:
						setCommandMode(3);
						setNumberOfCommands(6);
						break;
					case 5: 
						setCommandMode(3);
						setNumberOfCommands(6);
						break;
					case 6:
						setCommandMode(3);
						setNumberOfCommands(6);
						break;
					case 7:
						setCommandMode(3);
						setNumberOfCommands(6);
						break;
					case 8: 
						setCommandMode(3);
						setNumberOfCommands(6);
						break;
				}
			}
			else if(getCommandMode() == 2)
			{
				if(mode == "Cancel")
				{
					setCommandMode(0);
					setNumberOfCommands(3);
					
				}
				switch(selected)
				{					
					case 0:
						setCommandMode(0);
						setNumberOfCommands(3);
						break;
					case 1:
						setCommandMode(0);
						setNumberOfCommands(3);
						break;
				}
			}
			else if(getCommandMode() == 3)
			{
				if(mode == "Cancel")
				{
					setCommandMode(0);
					setNumberOfCommands(3);
					
				}
				switch(selected)
				{					
					case 0:
						setCommandMode(0);
						setNumberOfCommands(0);
						break;
					case 1:
						setCommandMode(0);
						setNumberOfCommands(0);
						break;
					case 2: 
						setCommandMode(0);
						setNumberOfCommands(0);
						break;
					case 3:
						setCommandMode(0);
						setNumberOfCommands(0);
						break;
					case 4:
						setCommandMode(0);
						setNumberOfCommands(0);
						break;
					case 5: 
						setCommandMode(0);
						setNumberOfCommands(0);
						break;
				}
			}
		}
		else
		{
			switch(selected)
			{
				case 0:
					this.die();
			}
		}
		
		
		return true;
	}
	
	/**************************************************************************************
	 * Author(s): Leszek Karcz, Changmin Bae
	 * returns list of possible commands
	 **************************************************************************************/
	public String[] getCommandsText()
	{
		if(this.isFinished())
		{
			if(getCommandMode() == 0)
				return new String[]{"Decommision",(this.getState()==0 ? "Power up" : "Power down"),"Research"};
			else if(getCommandMode() == 1)
				return new String[]{"Worker", "Explorer", "Range", "Melee", "Base", "Farm", "Fort", "Power Plant", "Smelter", "Watch Tower"};
			else if(getCommandMode() == 2)
				return new String[]{"Work Radius", "Worker Density"};
			else
				return new String[]{"Visibililty Radius","Defense Strength","Armor Strength","Movement Rate","Health","Efficiency"};			
		}
		else
		{
			return new String[]{"Cancel"};
		}
	}

	public void die()
	{ 
		super.die();
		player.removeLaboratory(this);
	}
}
